package cn.itcast.bos.system.service.impl;

import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.domain.security.Menu;
import cn.itcast.bos.domain.security.Role;
import cn.itcast.bos.domain.security.User;
import cn.itcast.bos.system.dao.UserDao;
import cn.itcast.bos.system.service.MenuService;
import cn.itcast.bos.system.service.RoleService;
import cn.itcast.bos.system.service.UserService;

@Service
@Transactional
public class UserServiceImpl implements UserService{
	@Autowired
	private UserDao userdao;
	@Autowired
	private RoleService roleService;
	@Autowired
	private MenuService menuServcie;
	private Logger logger=LoggerFactory.getLogger(getClass());
	@Override
	public User findByUsername(String username) {
		// TODO Auto-generated method stub
		return userdao.findByUsername(username);
	}
	@Override
	public List<User> show() {
		// TODO Auto-generated method stub
		return userdao.findAll();
	}
	@Override
	public void add(User t, Integer[] roleIds) {
		// TODO Auto-generated method stub
		List <Role> roles=roleService.getByIds(roleIds);
		t.getRoles().addAll(roles);
		userdao.save(t);
	}
	@Override
	public List<Menu> showMenus() {
		// TODO Auto-generated method stub
		Subject subject = SecurityUtils.getSubject();
		User user=(User) subject.getPrincipal();
		logger.info("当前用户名字为{},id为{}",user.getNickname(),user.getId());
		List<Menu> showMenus = menuServcie.showMenus(user.getId());
		logger.info("菜单的长度为：{}",showMenus.size());
		for (Menu menu : showMenus) {
			
		}
		return showMenus;
	}

}
